package com.leoandroid.tool.toolsbox.largeread.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.constraintlayout.widget.ConstraintLayout;

import com.leoandroid.tool.toolsbox.largeread.R;

public class AlarmLightActivity extends BaseActivity{

    private ConstraintLayout layoutAlarm;
    private LinearLayout layoutClose;
    private ImageView imgAlarm;

    private static final int MSG_ALARM_RED = 1;
    private static final int MSG_ALARM_BLUE = 2;


    private static final int DELAY_TIME = 200;


    @SuppressLint("HandlerLeak")
    private Handler mhandler = new  Handler(){
        // 通过复写handlerMessage()从而确定更新UI的操作
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case MSG_ALARM_RED:
                    layoutAlarm.setBackgroundColor(getResources().getColor(R.color.blue));
                    imgAlarm.setImageResource(R.mipmap.img_multifunction_police_lights_blue);
                    mhandler.sendEmptyMessageDelayed(MSG_ALARM_BLUE, DELAY_TIME);
                    break;
                case MSG_ALARM_BLUE:
                    layoutAlarm.setBackgroundColor(getResources().getColor(R.color.red));
                    imgAlarm.setImageResource(R.mipmap.img_multifunction_police_lights_red);
                    mhandler.sendEmptyMessageDelayed(MSG_ALARM_RED, DELAY_TIME);
                    break;
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alarm_light);
        initView();
        mhandler.sendEmptyMessageDelayed(MSG_ALARM_BLUE, DELAY_TIME);
    }

    private void initView(){
        layoutAlarm = findViewById(R.id.layout_alarm);
        imgAlarm = findViewById(R.id.img_alarm);
        layoutClose = findViewById(R.id.layout_close);

        layoutClose.setOnClickListener(view -> {
            finish();
        });
    }
}
